package com.foreveross.proxyip.infra.base.ddd.domain;

import java.io.Serializable;
import java.util.List;

import com.dayatang.domain.InstanceFactory;
import com.foreveross.proxyip.infra.base.ddd.repository.EntityHibernateRepository;
import com.foreveross.proxyip.infra.base.ddd.repository.IBaseRepository;
/**
 * 实体基类
 *  @author xiangsf 2013-2-16
 *
 */
public abstract class BaseEntity implements IBaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4945062958387483723L;
	
	private Serializable id;

	public Serializable getId() {
		return id;
	}

	public void setId(Serializable id) {
		this.id = id;
	}

	@Override
	public IBaseRepository getBaseEntityRepository() {
		return InstanceFactory.getInstance(EntityHibernateRepository.class, "entityHibernateRepository");
	}

	/**
	 * 根据ID获取实体
	 * @param id
	 * @return
	 */
	public IBaseEntity get(Serializable id){
		return getBaseEntityRepository().get(this.getClass(), id);
	}
	/**
	 * 是否存在ID的实体
	* @return boolean
	 */
	public boolean exists(Serializable id){
		return getBaseEntityRepository().exists(this.getClass(), id);
	}
	/**
	 * 获取实体列表
	 * @return
	 */
	public List<? extends BaseEntity> findAll(){
		return getBaseEntityRepository().findAll(this.getClass());
	}
	/**
	 * 创建实体
	 * @param o
	 */
	public void create(){
		getBaseEntityRepository().create(this);
	}

	/**
	 * 更新实体
	 * @param o 实体对象
	 */
	public void update(){
		getBaseEntityRepository().update(this);
	}

	/**
	 * 删除实体对象
	 * @param o
	 */
	public void delete(){
		getBaseEntityRepository().delete(this);
	}
	
	/**
	 * 删除保存实体对象
	 * @param o
	 */
	public void save(){
		getBaseEntityRepository().save(this);
	}
	
	
	@Override
	public boolean isNew() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean existed() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean notExisted() {
		return false;
	}

	@Override
	public boolean existed(String propertyName, Object propertyValue) {
		return false;
	}
}
